package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.TopicBean;
import com.project.bean.UserBean;
import com.project.service.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("topic")
public class TopicController {
    @Autowired
    private ITopicService topicService;

    @RequestMapping("findByItem")
    public PageInfo<TopicBean> findByItem(int channelId, int pageNO, String name,
                                          String userName, LocalDate startDate,LocalDate endDate){
        return topicService.findByItem(channelId,pageNO,name,userName,startDate,endDate);
    }

    @RequestMapping("add")
    public String add(String name, String info,int channelId, HttpServletRequest request){
        UserBean userBean = (UserBean) request.getSession().getAttribute("loginUser");
        topicService.add(new TopicBean(name,info,userBean.getId(),channelId));
        return "ok";
    }

    @RequestMapping("findById")
    public TopicBean findById(int id){
        return topicService.findById(id);
    }
}
